/**
 * @Author:Geln Yang
 * @Created:2008-9-30 $ Revision: 1.0 $ $ Author: Geln Yang $ $ Date: 2008-9-30 $
 */
package com.hgy.commonsale.webui.action.user;

import java.util.Date;

import org.geln.web.status.Status;

import com.hgy.commonsale.user.domain.User;
import com.hgy.commonsale.webui.action.ProtectedAction;

/**
 * @Author:Geln Yang
 * @Created:2008-9-30
 */
public class SaveUserAction extends ProtectedAction {
	private User user;

	@Override
	public String execute() throws Exception {
		if (user == null) {
			return ERROR;
		}
		if (user.getId() == null || user.getId().trim().length() == 0) {
			user.setRegistrationTime(new Date());
			user.setLastLoginTime(new Date());
			user.setLastLoginIP(getClientIPAddress());
		}
		Status resultStatus = userManager.saveOrUpdate(user);
		if (!resultStatus.equals(Status.SUCCESS)) {
			addActionError(getText("user.save.failed", new String[] { resultStatus.toString() }));
			return ERROR;
		}
		return SUCCESS;
	}

	public User getUser() {
		return user;
	}

	public void setUser(User user) {
		this.user = user;
	}
}
